home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Tool Chest / Developer Utilities / Installer 4.0.3 SDK / Script Examples / Action Atoms [inaa] Example / atom0.c next >
Encoding:
Text File  |  1994-11-15  |  4.2 KB  |  146 lines  |  [TEXT/MPS ]

  1. //
  2. //    Atom0.c
  3. //
  4. //        Demonstration of a format0 action atom.
  5. //
  6. //        A dialog is provided that allows the user to select
  7. //        the return value for the action atom. 
  8. //
  9. //        Scriptwriters should be aware that the return values
  10. //        and the actions that they invoke from the installer
  11. //        are different depending on which format of action atom
  12. //        is being used. 
  13. //
  14. //        NOTE: Displaying dialogs from within an action atoms 
  15. //        can enhance or detract from the user experience, and 
  16. //        should be done with consideration to the overall flow
  17. //        of installation. A good rule of thumb is to never display
  18. //        dialogs from an action atom unless absolutely necessary.
  19. //        This example is very useful in demonstrating behavior of
  20. //        the installer in regards to return values from an action
  21. //        atom, but is a terrible example of user interface design.
  22. //
  23. //        mark young • 07/10/94    
  24. //
  25. //        Copyright 1993-1994, Apple Computer, Inc., All Rights Reserved
  26. //
  27.  
  28. #include <Traps.h>
  29. #include <Types.h>
  30. #include <dialogs.h>
  31.  
  32. // this line replaces #include "ActionAtomIntf.h" used in Installer 3.x action atoms
  33. #include "ActionAtomHeader.h"
  34.  
  35. // this is needed for highliting the default button in dialog
  36. pascal OSErr SetDialogDefaultItem (    DialogPtr theDialog,
  37.                                     short newItem         ) = {0x303C,0x0304,0xAA68};
  38.  
  39. // NOTE: The name of this function 'ActionAtomFormat0' should
  40. // match that specified in the -m option for the line in the
  41. // makefile that compiles this action atom.
  42. pascal Boolean ActionAtomFormat0( AAPBRecPtr atomRecPtr )
  43. {
  44.  
  45.     DialogPtr    theDialog;                    // for dialog
  46.     OSErr        theOSError = 0;                // for errors
  47.     
  48.     short        theItemHit;                    // gets user response from ModalDialog()
  49.     short        iType;                        // gets control type from GetDItem()
  50.     Handle        iHandle;                    // gets control handle from GetDItem()
  51.     Rect         iRect;                        // gets control rect from GetDItem()
  52.     
  53.     short        currRadioButton = 2;        // current selected radio button
  54.     short        gettingUserResponse = true;    // flag for while loop
  55.     
  56.     short        theStatus = 0;                // value to return from function
  57.  
  58.     // this gets rid of those annoying messages during MPW compiles
  59.     // informing us that certain items were not used
  60.     #pragma unused( atomRecPtr )
  61.  
  62.     // retrieve DLOG/DITL 128 from compiled resource script
  63.     theDialog = GetNewDialog( 128, nil, (WindowPtr) -1 );
  64.  
  65.     // activate OK button when enter or return key is pressed
  66.     theOSError = SetDialogDefaultItem( theDialog, 1 );
  67.  
  68.     // set up the radio button group ( controls 2 - 3 )
  69.     GetDItem( theDialog, 2, &iType, &iHandle, &iRect);
  70.     SetCtlValue( (ControlHandle) iHandle, 1 );    
  71.     
  72.     GetDItem( theDialog, 3, &iType, &iHandle, &iRect);
  73.     SetCtlValue( (ControlHandle) iHandle, 0 );    
  74.         
  75.     // select the new dialog
  76.     SelectWindow( (WindowPtr) theDialog );
  77.     
  78.     // show the new dialog
  79.     ShowWindow( (WindowPtr) theDialog );
  80.     
  81.     // keep getting response from user until
  82.     // the OK is activated in the new dialog
  83.     gettingUserResponse = true;
  84.     while ( gettingUserResponse )
  85.         {
  86.         // get user selection from the new dialog
  87.         ModalDialog( nil, &theItemHit );
  88.         switch ( theItemHit )
  89.             {
  90.             // first control is the OK key
  91.             case( 1 ) : 
  92.                         // exit loop
  93.                         gettingUserResponse = false;
  94.                         break;
  95.                         
  96.             // all other controls in dialog are radio buttons
  97.             default :     
  98.                         // continue with loop
  99.                         gettingUserResponse = true;
  100.                         
  101.                         // if the radio button selection changed
  102.                         if ( currRadioButton != theItemHit )
  103.                             {
  104.                             // turn previous radio button off
  105.                             GetDItem( theDialog, currRadioButton, &iType, &iHandle, &iRect);
  106.                             SetCtlValue(  (ControlHandle) iHandle, 0 );    
  107.         
  108.                             // turn current radio button on
  109.                             GetDItem( theDialog, theItemHit, &iType, &iHandle, &iRect);
  110.                             SetCtlValue(  (ControlHandle) iHandle, 1 );    
  111.         
  112.                             // save current radio button choice
  113.                             currRadioButton = theItemHit;
  114.                             }
  115.                         break;
  116.             }// switch
  117.  
  118.         }// while
  119.         
  120.     // get rid of the new dialog
  121.     DisposDialog( theDialog );
  122.  
  123.     // select a value to return from this function according to
  124.     // which radio button was selected in the dialog
  125.     switch ( currRadioButton )
  126.         {
  127.         // return false
  128.         case( 2 ) : theStatus = false;    // user selected to return 0
  129.                     break;
  130.                     
  131.         // return true
  132.         case( 3 ) : theStatus = true;    // user selected to return 1
  133.                     break;
  134.                     
  135.         }
  136.         
  137.     // return value selected by user in dialog
  138.     return( theStatus );
  139.  
  140. }
  141.  
  142.  
  143.  
  144.  
  145.  
  146.